<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        修改申请单选择配件
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">

</head>

<style>

</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app" style="height: 410px;">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>数量</label>
                    <div style="width: 80%" class="layui-input-inline">
                        <input  autocomplete="off"  lay-filter="num" type="number" name="num"
                               lay-verify="required" min="0" placeholder="数量" class="layui-input">
                    </div>
                </div>

                <input  autocomplete="off"  lay-filter=“pty” type="hidden" name="pty" min="0" placeholder="xx" class="layui-input">

                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>有无偿</label>
                    <div style="width: 80%" class="layui-input-inline">
                        <select  class="partsType"  lay-filter="partsType" name="partsType"  id="partsType"  lay-search="">

                        </select>
                    </div>
                </div>

            </div>
        </div>

    </form>
</div>
<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>


    $(function () {
        var parse = JSON.parse(localStorage.getItem('request_edit_parts'));
        $("input[name=num]").val(parse.num);
        $("input[name=pty]").val(parse.partsType);

        $("input[name=num]").on("input", function (e) {
            parse.num = e.delegateTarget.value;
            parse.partsType = $('#partsType option:selected') .val();
            localStorage.setItem('request_edit_parts', JSON.stringify(parse))
        });


        layui.use(['form'],
            function () {
                var form = layui.form;
                form.on('select(partsType)', function (data) {
                    console.log(data);
                    parse.partsType = data.value;
                    localStorage.setItem('request_edit_parts', JSON.stringify(parse))
                });
            });



    });


    setTimeout(() => {
        //有无偿
        let form = layui.form;
        let request = {
            url: 'kf/dictionary/getValue',
            data: {
                userId: $userId,
                dictionaryCode: 'repay_type'
            },
            method: "GET",
        };
        sendRequest(request, (res) => {
            let a = $("input[name='pty']").val();
            console.log(a);
            let d = res.data;
            $.each(d, function (index, item) {
                let opt;
                if(item.type === a ){
                    opt = $("<option selected value=" + item.type + ">" + item.name + "</option>");
                }else{
                    opt = $("<option value=" + item.type + ">" + item.name + "</option>");
                }
                $("select[name=partsType]").append(opt);
            });
            form.render('select');
        });
    }, 300)


</script>

</body>

</html>
